
/**
 * Project Name:cats-web
 * File Name:UserController.java
 * Package Name:com.catsic.web.controllers
 * Date:2014年4月3日上午9:03:56
 * Copyright (c) 2014, oa.catsic.com All Rights Reserved.
 */
 
package com.catsic.web.controllers;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.catsic.base.controller.BaseController;
import com.catsic.core.depart.service.DepartService;
import com.catsic.core.form.DepartForm;

/**
 * ClassName: DepartController
 * Description: 部门Controller
 * date: 2014年4月3日 上午9:03:56
 * author: yangyd
 */
@Controller
@RequestMapping("/depart")
public class DepartController extends BaseController{
	
	@Autowired
	private DepartService departService;
	
	/**
	 * create:创建
	 * @author yangyd
	 * @param form
	 * @return
	 */
	@RequestMapping(value = "/create" , method = RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> create(DepartForm form){
		form = departService.add(form);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put(CONTENT, form);
		map.put(RESULT, RESULT_SUCCESS);
		return map;
	}
	
	/**
	 * update:更新
	 * @author yangyd
	 * @param form
	 * @return
	 */
	@RequestMapping(value = "/update" , method = RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> update(DepartForm form){
		form = departService.update(form);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put(CONTENT, form);
		map.put(RESULT, RESULT_SUCCESS);
		return map;
	}
	
	/**
	 * delete:删除
	 * @author yangyd
	 * @param id
	 * @return Depart
	 */
	@RequestMapping(value = "/delete")
	@ResponseBody
	public Map<String,Object> delete(String id){
		departService.delete(id);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put(RESULT, RESULT_SUCCESS);
		return map;
	}
	
	/**
	 * detail:详情
	 * @author yangyd
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/detail")
	@ResponseBody
	public Map<String,Object> detail(String id){
		Map<String,Object> map = new HashMap<String,Object>();
		map.put(CONTENT, departService.findDepartById(id));
		map.put(RESULT, RESULT_SUCCESS);
		return map;
	}
	
	/**
	 * query:通过机构ID查询该机构所有部门
	 * @author yangyd
	 * @param form
	 * @return
	 */
	@RequestMapping(value = "/query" , method = RequestMethod.GET)
	@ResponseBody
	public Map<String,Object> query(String organId){
		List<DepartForm> form = departService.query(organId);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put(CONTENT,form);
		map.put(RESULT,RESULT_SUCCESS);
		return map;
	}
}
